package com.lianqi.emcpframework.design.support.event;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.lianqi.emcpframework.core.generator.IDGenerator;
import com.lianqi.emcpframework.design.domain.event.DomainEvent;
import com.google.common.base.Preconditions;

/**
 * @program emcp-framework
 * @ClassName AbstractDomainEvent
 * @description: 抽象领域事件定义
 * @author: sky
 * @create: 2019/06/06 19:32
 */
public abstract class AbstractDomainEvent implements DomainEvent {

    private final String id;

    private final Date createTime;

    /**
     * 构造方法
     * 
     * @param id
     *            事件ID
     */
    protected AbstractDomainEvent(String id) {
        Preconditions.checkArgument(StringUtils.isNotEmpty(id));
        this.id = id;
        this.createTime = new Date();
    }

    /**
     * 构造方法
     */
    protected AbstractDomainEvent() {
        this(IDGenerator.SNOW_FLAKE_STRING.generate());
    }

    @Override
    public String id() {
        return id;
    }

    @Override
    public Date occurredOn() {
        return this.createTime;
    }
}
